package com.njtoyo.taxi.admin.library.security;

import cn.hutool.crypto.digest.BCrypt;

/**
 * @Author Dell
 * @Date 2021/6/9 14:52
 */
public abstract class PwdHelper {

    /**
     * 生成密码
     * @param plainText
     * @return
     */
    public static String generatePwd(String plainText) {
        String result = BCrypt.hashpw(plainText);
        return "$2y"+result.substring(3);
    }

    /**
     * 校验密码
     * @param input
     * @param hashPwd
     * @return
     */
    public static Boolean validPwd(String input,String hashPwd){
        if(hashPwd.startsWith("$2y")){
            hashPwd = "$2a" + hashPwd.substring(3);
        }
        return BCrypt.checkpw(input,hashPwd);
    }

}
